package com.yz.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yz.book.entity.User;
import com.yz.book.mapper.UserMapper;
import com.yz.book.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ste
 * @since 2023-02-04 03:37:37
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    UserMapper userMapper;

    public User getUserByUsername(String username){

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);

        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    @Override
    public User getUserByEmail(String email) {

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("email",email);

        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    @Override
    public void reg(String username, String password, String tel, String email) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setTel(tel);
        user.setEmail(email);

        userMapper.insert(user);
    }

}
